<?php

use console\db\channels\TransferTableMigration;

/**
 * 文章频道转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300010_000012_t_cms_channel extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'cms_channel' => 'ts_channel',
            ],
            'columns' => [
                'id',
                'name',
                'abbr' => 'name',
                'template' => function() {
                    return '';
                },
                'link',
                'listorder',
                'recommend_at' => function($data) {
                    if ($data['recommend']) {
                        return strtotime('-1 year');
                    }
                    return 0;
                },
                'status' => function($data) {
                    if ($data['status'] > 0) {
                        return 10;
                    }
                    return 0;
                },
                'created_at' => function($data) {
                    if ($data['created_at'] > strtotime('-3 year')) {
                        return $data['created_at'];
                    }
                    return strtotime('-2 year');
                },
                'updated_at' => function($data) {
                    if ($data['updated_at'] > strtotime('-3 year')) {
                        return $data['updated_at'];
                    }
                    return strtotime('-1 year');
                },
                'deleted_at' => function($data) {
                    if ($data['status'] < 0) {
                        return $data['updated_at'];
                    }
                    return 0;
                },
            ],
        ];
    }

}
